package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDAOperatorEQPWorkRequestController {

    def commentService

    def index() {
        def result = ResultModel.getResultModel()
        try {
            def USERNAME = params.USERNAME?:""
            def body = [USERNAME:USERNAME]
            def MACHINENAME = params.MACHINENAME ?: "aa"

            Header header = new Header(TRANSACTIONID: Utils.getUUID(), MESSAGENAME: "PDAOperatorEQPWorkRequest", MACHINENAME: MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header, body: body, aReturn: aReturn)

//            result = commentService.getJsonByTopic2Queue_1(requestModel,"sendmqname","returnmqname",true,responseXml)

            result = commentService.getJsonByTopic2Queue_1(requestModel, "jms.topic.PDA.TO.CIM", "jms.queue.CIM.PDA.Send", false, false)

        } catch (Exception e) {
            result.put(ResultModel.ServerErrorFlag, true)
            result.put(ResultModel.Code, ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg, ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data, e.getMessage())
        } finally {
            render Utils.getFormatString(result)
        }
    }

    def responseXml = """
<MESSAGE>
<HEADER>
  <TRANSACTIONID>29f803c9-5188-43c1-bebb-65e527ddd4a1</TRANSACTIONID>
  <MESSAGENAME>PDAOperatorEQPWorkResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>2</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-04-11 15:51:59.151</EVENTTIME>
</HEADER>
<BODY>
  <EQPWORKQTYLIST>
    <EQPWORKQTY>
      <EQPID>DB-447</EQPID>
      <DONEQTY>1000</DONEQTY>
    </EQPWORKQTY>
    <EQPWORKQTY>
      <EQPID>DB-448</EQPID>
      <DONEQTY>2000</DONEQTY>
    </EQPWORKQTY>
    <EQPWORKQTY>
      <EQPID>DB-449</EQPID>
      <DONEQTY>3000</DONEQTY>
    </EQPWORKQTY>
  </EQPWORKQTYLIST>
  <USERNAME>1000000</USERNAME>
</BODY>
<RETURN>
  <RETURNCODE />
  <RETURNMESSAGE />
</RETURN>
</MESSAGE>
"""
}
